package com.example.multithread.debugtest;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.stream.IntStream;

/**
 * @ClassName DebugTest
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2020/6/4 9:16 AM
 * @Version 1.0
 */
@Slf4j
public class DebugTest {
	public static void main(String[] args) {
		ExecutorService executorService = Executors.newFixedThreadPool(3, new ThreadFactory() {
			@Override
			public Thread newThread(Runnable r) {
				Thread t1 = new Thread(r);
				t1.setDaemon(true);
				return t1;
			}
		});
		IntStream.rangeClosed(1, 3).forEach(i-> executorService.execute(DebugTest::doSomething));
		executorService.shutdown();
		while (true) {
			if (executorService.isTerminated()) {
				break;
			}
		}
	}

	public static void doSomething() {
		log.info(Thread.currentThread().getName());
		log.info("----------");
	}
}
